package com.rdgk.newtech.controller;

import com.alibaba.fastjson.JSONObject;
import com.rdgk.newtech.service.OrgAnalyseService;
import com.rdgk.newtech.service.ProjectService;
import com.rdgk.newtech.util.CommonUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: bguan
 * @description: 机构动态Controller
 */
@RestController
@RequestMapping("/organalyse")
public class OrgAnalyseController {

	@Autowired
	private OrgAnalyseService orgAnalyseService;

	/**
	 * 重点机构列表
	 */
	@PostMapping("/importantOrgList")
	public JSONObject importantOrgList(HttpServletRequest request) {
		String topicId = request.getParameter("topicId");
		String count = request.getParameter("count");
		if(StringUtils.isEmpty(count))
		return CommonUtil.successJson(orgAnalyseService.importantOrgList(Integer.parseInt(topicId),null));
		else
			return CommonUtil.successJson(orgAnalyseService.importantOrgList(Integer.parseInt(topicId),null,count));

	}

    /**
     * 机构动态信息区域分布
     */
    @PostMapping("/technologyRegionalDistribution")
    public JSONObject technologyRegionalDistribution(HttpServletRequest request) {
		String topicId = request.getParameter("topicId");
        return CommonUtil.successJson(orgAnalyseService.technologyRegionalDistribution(Integer.parseInt(topicId),null));
    }

	/**
	 * 某个专题下面所有机构合作关系
	 */
	@PostMapping("/allOrgCooperateNet")
	public JSONObject allOrgCooperateNet(HttpServletRequest request) {
		String topicId = request.getParameter("topicId");
		String keyword = request.getParameter("keyword");
		return CommonUtil.successJson(orgAnalyseService.allOrgCooperateNet(Integer.parseInt(topicId),keyword));
	}

	/**
	 * 获取某个机构的详细信息
	 */
	@PostMapping("/orgDetails")
	public JSONObject orgDetails(HttpServletRequest request) {
		String topicId = request.getParameter("topicId");
		String orgId = request.getParameter("orgId");
		return CommonUtil.successJson(orgAnalyseService.orgDetails(Integer.parseInt(topicId),Integer.parseInt(orgId)));
	}
	/**
	 * 获取某个机构的详细信息
	 */
	@PostMapping("/orgTechEventDetails")
	public JSONObject orgTechEventDetails(HttpServletRequest request) {
		String topicId = request.getParameter("topicId");
		String orgId = request.getParameter("orgId");
		String type = request.getParameter("type");

		String startDate = request.getParameter("startDate");
		String endDate = request.getParameter("endDate");

		Map<String,Object> params = new HashMap<String,Object>();
		params.put("topicId",topicId);
		params.put("orgId",orgId);
		params.put("startDate",startDate);
		params.put("endDate",endDate);

		if("0".equals(type))
			if(StringUtils.isEmpty(startDate) || StringUtils.isEmpty(endDate))
				return CommonUtil.successJson(orgAnalyseService.orgTechDetails(Integer.parseInt(topicId),Integer.parseInt(orgId)));
			else
				return CommonUtil.successJson(orgAnalyseService.orgTechDetails(params));

		else if("1".equals(type))
			if(StringUtils.isEmpty(startDate) || StringUtils.isEmpty(endDate)) {
				return CommonUtil.successJson(orgAnalyseService.orgPaperDetails(Integer.parseInt(topicId),Integer.parseInt(orgId)));
			}
			else {
				return CommonUtil.successJson(orgAnalyseService.orgPaperDetails(params));
			}

		else
			if(StringUtils.isEmpty(startDate) || StringUtils.isEmpty(endDate))
				return CommonUtil.successJson(orgAnalyseService.orgPatentDetails(Integer.parseInt(topicId),Integer.parseInt(orgId)));
			else
				return CommonUtil.successJson(orgAnalyseService.orgPatentDetails(params));
	}
}
